refactor: make KetchLogger a class with tag constructor parameter#99
Merged
refactor: make KetchLogger a class with tag constructor parameter#99
Conversation
Convert KetchLogger from a singleton object to a normal class that
takes a tag parameter in its constructor. Each component now creates
its own KetchLogger instance, eliminating the redundant tag parameter
from every logging call.
Before: KetchLogger.d("Coordinator") { "message" }
After: log.d { "message" } // where log = KetchLogger("Coordinator")
The global Logger backend remains in the companion object, set once
by the Ketch instance and shared across all KetchLogger instances.
https://claude.ai/code/session_01NxdYLTBc1qtKTGDL823wNz
Contributor
All logging methods are now `inline` with a reference-equality check against Logger.None. When logging is disabled (the default): - The outer message lambda is eliminated by inlining (no allocation) - The inner tag-wrapper lambda is skipped by the fast-path check - Result: true zero-cost logging — no allocations, no virtual calls When logging is enabled, the only overhead vs before is one cheap reference comparison per call. https://claude.ai/code/session_01NxdYLTBc1qtKTGDL823wNz
KetchLogger's inline functions with Logger.None fast-path already handle lazy evaluation, so Logger implementations don't need lambdas. This simplifies the Logger interface and eliminates an inner lambda allocation per log call. https://claude.ai/code/session_01NxdYLTBc1qtKTGDL823wNz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactored the logging system from a static object-based approach to an instance-based approach where each component creates its own
KetchLoggerinstance with a descriptive tag. This improves code clarity and reduces boilerplate by eliminating the need to pass tag strings to every logging call.Key Changes
KetchLogger refactoring: Converted
KetchLoggerfrom a static object with tag parameters to a class that takes atagin its constructorv,d,i,w,e) no longer requires a tag parameterLoggerbackend is now managed via a companion object[tag]Component logger instances: Added private
logproperty to all major components:Ketch- uses tag "Ketch"DownloadCoordinator- uses tag "Coordinator"HttpDownloadSource- uses tag "HttpSource"DownloadScheduler- uses tag "Scheduler"ScheduleManager- uses tag "ScheduleManager"KtorHttpEngine- uses tag "KtorHttpEngine"SourceResolver- uses tag "SourceResolver"SegmentDownloader- uses tag "SegmentDownloader"RangeSupportDetector- uses tag "RangeDetector"TokenBucket- uses tag "TokenBucket"KetchServer- uses tag "KetchServer"NativeMdnsRegistrar- uses tag "NativeMdnsRegistrar"KetchService- uses tag "KetchService"Updated all logging calls: Replaced all
KetchLogger.x("Tag")calls withlog.x()throughout the codebaseRemoved TAG constants: Eliminated hardcoded
TAGcompanion object constants fromKetchServiceandKetchServeras they're no longer neededImplementation Details
The refactoring maintains backward compatibility with the existing
Loggerinterface while improving the developer experience:[ComponentName]in all log messagesKetchLogger.setLogger()https://claude.ai/code/session_01NxdYLTBc1qtKTGDL823wNz